-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[red-knot] Include vendored typeshed stubs as a zipfile in the Ruff binary #11779
Conversation
Looks good! Did you (manually) verify that changing a file in the vendored typeshed directory triggers a rebuild of the zip and the changed contents show up in the binary? (Eg delete |
Tried that out, and it looks good! Now to make it work on Windows... |
|
🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work. I've some questions before approving
- What's the binary size increase?
- What's the build time increase on an incremental (change to a rust file) and clean build. You can get the timings with
cargo build --timings -p red_knot
- Did you open a created archive. Does it look correct?
crates/red_knot/build.rs
Outdated
// Write file or directory explicitly | ||
// Some unzip tools unzip files with directory paths correctly, some do not! | ||
if path.is_file() { | ||
println!("adding file {path:?} as {name:?} ..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the println statements? Especially if they clutter the CLI output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Co-authored-by: Micha Reiser <[email protected]>
On
With this PR branch:
The
On |
We're definitely able to inspect the contents of files in the zip at runtime using the I also managed to inspect the filenames in the zip using Python's I've been struggling to extract the zip archive or inspect the contents of any of the files in the zip from outside Rust -- most tools for unzipping zip archives don't seem to expect the |
Sorry, I should have been more explicit. Can you compare the release build numbers. Also, The red knot binary size is identical. I think the typeshed files should be larger than 0 bytes? Ohhh, maybe the compiler optimizes them away (or isn't part of the executable anymore if you moved it to tests) |
Yeah, this confused me as well, since the length of the
No worries, I'll do that! |
With
PR branch:
So, still not showing up in the size of the binary (even though it's definitely compiling all the test features as part of that command. Still, we know how large the zip is from this:
|
In c5ad832, I switched to setting the location of the zip (relative to cargo's |
@AlexWaygood what's the benefit of the environment variable for the name of the zip? It feels like unnecessary complexity to me, considering that we don't have a use case for a different name. If it's just to avoid the path repetition, then I think adding a comment to Edit: Like I'm not against it, but it makes the code harder to follow. I then need to search for where the environment variable comes from and understand if there's actually a use case where we want to change the path. Having it hard coded makes it very explicit and failing to update the path in one file will also give you compile errors right away. |
Yes, it was just to avoid the repetition, and to make it so that there was a "single source of truth" for the location. It felt more "principled" to me. But I also wasn't sure if it was worth the new complexity, so I'll revert it if you find it less readable 👍 |
This reverts commit c5ad832.
I think it's just slightly over-engineered ;) |
Thanks both for the reviews! |
Summary
Work towards #11653.
This PR adds a
build.rs
script to thered_knot
crate that compresses our vendored typeshed stubs into a zip that is then included in the Ruff binary viainclude_bytes!()
inmodule.rs
. This will enable us to resolve modules to vendored stdlib stubs from typeshed in the future.Details:
build.rs
script is run before anything else in the crate is builtcargo:rerun-if-changed
directive to stdout to let Cargo know that thebuild.rs
only needs to be rerun if the contents ofcrates/red_knot/vendor/typeshed
changes, or if thebuild.rs
script itself changes. Docs here: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rerun-if-changed. We need to use a syntax for this directive that's officially deprecated, due to the fact that our pinned minimum Rust version is old enough that it doesn't support the new version. (The deprecated syntax iscargo:rerun-if-changed=
, with one colon. The new syntax usescargo::rerun-if-changed=
, with two colons.).gitignored
. Unfortunately there will be a need to manually keep that.gitignore
entry in sync with the hardcoded path inbuild.rs
.zip
crate. Following the precedent in Concerns with zip version 1.x uv#3642, I pinned to an old version of thezip
crate, and added a Renovate rule to make sure that we don't get dependency-update PRs for that crate.Test Plan
Some basic tests have been added that show that the zip archive containing typeshed is available from the Ruff after it has been built, and that the zip archive has some stdlib stubs in it.